#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 2e5 + 5;
int T, n, a[N], b[N], ans;
//set dp[i][j]
//i means the number, j means

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    freopen("color1.in", "r", stdin);
    freopen("color.out", "w", stdout);

    cin >> T;
    while (T--){
        ans = 0;
        cin >> n;
        for (int i = 1; i <= n; i++){
            cin >> a[i]; b[i] = 0;
        }
        for (int i = n; i >= 1; i--){
            b[i] = (i % 2) + 1;
            for (int j = i - 1; j >= 1; j--){
                if (a[i] == a[j]){
                    ans += a[i];
                    b[j] = b[i];
                    b[j-1] = 3 - b[i];
                    break;
                }else{
                    if (b[i] == b[j]) break;
                }
            }
        }
        cout << ans << '\n';
    }

    return 0;
}
